import { Collect } from '../models/collect'
const collectModel = new Collect()

export default function collectFun(type, id, isCancel, callback) {
  if(!wx.getStorageSync('userToken')){
    wx.showToast({
      title: '请先登录',
      icon: 'none'
    })
    wx.navigateTo({
      url: `/pages/login/login`
    })
    return
  }
  if (isCancel) {
    collectModel.cancelCollect({
      collectType: type,
      collectId: id
    }, callback)
  } else {
    collectModel.collect({
      collectType: type,
      collectId: id
    }, res => {
      wx.showToast({
        title: '收藏成功！',
        icon: 'none'
      })
      callback(res)
    })
  }
}